#include <iostream>
#include <thread>
#include <chrono>

#include "../Utility/trace.h"

using namespace std;

class BackgroundTask
{
public:
    BackgroundTask()
    {
        TRACE() << "constructor: " << this_thread::get_id() << endl;
    }

    BackgroundTask(BackgroundTask &/*task*/)
    {
        TRACE() << "copy contructor: " << this_thread::get_id() << endl;
    }

    void operator()()
    {
        cout << "[" << __FUNCTION__ << "]" << this_thread::get_id() << endl;
        this_thread::sleep_for(chrono::seconds(5));
        TRACE() << "Bye bye." << endl;
    }
};

int main()
{
    TRACE() << "Hello World!" << endl;
    TRACE() << this_thread::get_id() << endl;
    BackgroundTask task;
    thread t(task);
//    t.join();
    t.detach();

//    thread t1((BackgroundTask()));
//    thread t1{BackgroundTask()};
//    t1.join();
//    thread t1([](){
//        TRACE() << this_thread::get_id() << endl;
//    });
//    t1.join();
    TRACE() << "Bye bye." << endl;
    return 0;
}
